import Vue from 'vue'


import 'normalize.css/normalize.css' // a modern alternative to CSS resets
import request from '@/utils/request'
import Element from 'element-ui'
import './assets/styles/element-variables.scss'
import '@/assets/styles/index.scss' // global css
import '@/assets/styles/ruoyi.scss' // ruoyi css
import 'font-awesome/css/font-awesome.min.css';


import App from './App'
import store from './store'
import router from './router'
import mvcjs from '@/utils/mvc'
import permission from './directive/permission'
import { gotoPage,loadTreeTable } from '@/api/menu'
import BaiduMap from 'vue-baidu-map'
import { download } from '@/utils/request'
import { errorMessage } from '@/api/menu'
import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
//import { getConfigKey } from "@/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, handleTree } from "@/utils/ruoyi";
import Pagination from "@/components/Pagination";
import defaultSettings from '@/settings'
import echarts from 'echarts'

window.js=mvcjs;
Vue.use(BaiduMap, {  ak:'RnvGZBIZtLSmeEUWKp1o578dcz3dh8F8' })
//import BootstrapVue from 'bootstrap-vue'
//Vue.use(BootstrapVue)
//import 'bootstrap/dist/css/bootstrap.css'
//import 'bootstrap-vue/dist/bootstrap-vue.css'
// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.initchart = function(obj){
	return echarts.init(obj);
}
//Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.download = download
Vue.prototype.process = process
Vue.prototype.handleTree = handleTree
Vue.prototype.mvc = window.mvc

Vue.prototype.msgSuccess = function (msg) {
  this.$message({ showClose: true, message: msg, type: "success" });
}

Vue.prototype.msgError = function (msg) {
  this.$message({ showClose: true, message: msg, type: "error" });
}

Vue.prototype.msgInfo = function (msg) {
  this.$message.info(msg);
}
Vue.prototype.console = window.console;



Vue.prototype.loadTreeTable = loadTreeTable
Vue.prototype.confirmURL = function(title,url){
	this.$confirm(title, '提示', {
	  confirmButtonText: '确定',
	  cancelButtonText: '取消',
	  type: 'warning',
	  center: true
	}).then((action) => {
		request({
			method: 'get',
			url: url,
		}).then(data => {
			this.$router.replace("/redirect"+this.$route.fullPath);
			this.msgSuccess(data.msg);
		})
	});
};
Vue.prototype.getValueName=function(values,_def){
	var ss=values.split(",");
	for(var k in ss) { 
		var option=ss[k].split("=");
		if (option.length==2){
			if (option[1].trim()==(""+_def)){
				return option[0].trim();
			}
		}
	}
	return _def;
}
Vue.prototype.getDateTime=function(values,_def){
	return values[_def];
}

Vue.prototype.gotoMenu=function(url){
	return this.gotoPage(url+"?"+this.vueparams);
}
Vue.prototype.getContainerMenu=function(menus){
	
}
Vue.prototype.postData=function(){
	var result={};
	var data=this.$data;
	var index=0;
	for (var k in data){
		if (["rules","Container"].indexOf(k)==-1){
			if ("jqcheck"==k){
				result["jqcheck"]=data[k].join();
			}else if ("pathInfo"==k){
				result["pathInfo"]=data[k];
			}else if (Array.isArray(data[k])){
				index++;
				for (var i in data[k]){
						result["element-"+index+""+i+".table"]=k;
					for (var ii in data[k][i]){
						result["element-"+index+""+i+".map.-"+ii]=data[k][i][ii];
					}
				}
			}else if(typeof(data[k])=="object"){
				for (var i in data[k]){
					result[i]=data[k][i];
				}
			}
		}
	}
	return result;
}
Vue.prototype.gotoPage = function(page,data) {
 var params=page.split("?");
 page=params[0];
 if (data!=undefined){
	if (params.length>1){
		params[1]=this.getDataParams(data)+params[1];
	}else{
		params.push(this.getDataParams(data));
	}
 }
	if (params.length>1){
		return gotoPage(page+"?"+params[1]);
	}else{
		return gotoPage(page);
	}
}
Vue.prototype.getDateTimeString=function(emt,data){
	return emt[data];
}
Vue.prototype.getDataParams=function(data){
	var ret="";
	for (var name in data){		
//		if (name=="CMCLASSID"||name=="CMODULEID"||name=="CPOPUP"||name.startsWith("CMID")){
		if (this.$route.fullPath.indexOf(name+"=")>0){		
			if (Array.isArray(data[name])){
				ret+="&"+name+"="+data[name][0];
			}else{
				ret+="&"+name+"="+data[name];
			}
		}
	}
	return ret;
}
Vue.prototype.getVUEParams=function(def){
	var ret="";
//	if (this.popparams){
//		ret=this.popparams;
//	}
	if (typeof(this.$parent.$parent.popparams)=="string"){
		ret+=this.$parent.$parent.popparams;
	}else if (typeof(this.$parent.$parent.popparams)=="object"){
//		for (var k in this.$parent.$parent.popparams){
//			$.extend(this[k], this.$parent.$parent.popparams[k]);
//		}
	}
	ret+=this.getDataParams(this.$route.query);
	return ret+def;
}
Vue.prototype.appendRow=function(list){
	var obj0=list[0],obj={};
	for (var o in obj0){
		obj[o]=null;
	}
	list.push(obj);
}
Vue.prototype.delRow=function(list,scope){
  if(list.length==1){
	  this.msgError("请至少保留一项");
	  return;
  }
  list.splice(scope.$index, 1);
}

Vue.prototype.loadContainerMenu=function(menu,name,appendurl){
	request({
		method: 'get',
		url: process.env.VUE_APP_LOGIN_API+"/VUELogin/ContainerMenu?"+appendurl,
		params:menu
	}).then(data=> {
		this[name]=data.rows;
	})
}


// 全局组件挂载
Vue.component('Pagination', Pagination)
// An highlighted block
Vue.component('remote-script', {

  render: function (createElement) {
    var self = this
    return createElement('script', {
      attrs: {
        type: 'text/javascript',
        src: process.env.VUE_APP_STATICCTX+this.src
      },
      on: {
        load: function (event) {
          self.$emit('load', event)
        },
        error: function (event) {
          self.$emit('error', event)
        },
        readystatechange: function (event) {
          if (this.readyState === 'complete') {
            self.$emit('load', event)
          }
        }
      }
    })
  },

  props: {
    src: {
      type: String,
      required: true
    }
  }
})

Vue.use(permission)

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: 'medium' // set element-ui default size
})



//Vue.config.productionTip = false
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
